// ulp.h - units in the last place
// Copyright (c) 2006-2011 KALX, LLC. All rights reserved. No warranty is made.
#pragma once

static_assert(sizeof(double) == sizeof(long long),
	"double and long long must have the same size");

inline long long ulp(double x, double y)
{
	union { double d; long long l; } ix, iy;

	ix.d = x;
	iy.d = y;

	if (ix.l < 0)
		ix.l = 0x8000000000000000LL - ix.l;

	if (iy.l < 0)
		iy.l = 0x8000000000000000LL - iy.l;

	return ix.l - iy.l;
}
